package com.winteam.View;

import com.winteam.Bean.Client;
import com.winteam.Controler.Select;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.table.DefaultTableModel;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import java.util.Vector;

import java.awt.Color;

public class CustManage extends JFrame {

	private JPanel contentPane;
	private JTextField serialField;
	private DefaultTableModel model;
	
	//背景颜色
	Color bg = new Color(231,215,183);
	
	public static void main(String[] args) {
		new CustManage();
	}
	/**
	 * Create the frame.
	 */
	public CustManage() {
		setDefaultCloseOperation(1);
		this.setSize(955,547);
		contentPane = new JPanel();
		contentPane.setBackground(bg);
		contentPane.setLayout(null);
		setContentPane(contentPane);
		this.setTitle("客户管理");
		
		
		JLabel serialLabel = new JLabel("来宾姓名/证件编号:");
		serialLabel.setFont(new Font("宋体", Font.BOLD, 20));
		serialLabel.setBounds(155, 48, 201, 25);
		contentPane.add(serialLabel);
		
		//查询输入框
		serialField = new JTextField();
		serialField.setBounds(366, 48, 184, 25);
		contentPane.add(serialField);
		serialField.setColumns(10);
		
		//查询按钮
		JButton queryButton = new JButton("查询",new ImageIcon(getClass().getResource("img/find.gif")));
		queryButton.setFont(new Font("宋体", Font.BOLD, 16));
		queryButton.setBounds(574, 44, 97, 33);
		contentPane.add(queryButton);
		queryButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				setModel(new Select().findAllCllient(serialField.getText()));
			}
		});
		
		//刷新按钮
		JButton updateButto = new JButton("退出",new ImageIcon(getClass().getResource("img/cancel.gif")));
		updateButto.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				dispose();
			}
		});

		updateButto.setFont(new Font("宋体", Font.BOLD, 16));
		updateButto.setBounds(699, 44, 97, 33);
		contentPane.add(updateButto);
		updateButto.setOpaque(false);
		queryButton.setOpaque(false);
		queryButton.setBackground(new Color(231,215,183));
		updateButto.setBackground(new Color(231,215,183));
		JLabel lblNewLabel = new JLabel("来  宾  信  息");
		lblNewLabel.setFont(new Font("宋体", Font.BOLD, 18));
		lblNewLabel.setBounds(392, 107, 200, 33);
		contentPane.add(lblNewLabel);
		
		//设置表格
		setModel(new Select().findAllCllient());
		JTable table = new JTable(model);
		JScrollPane infolPane = new JScrollPane(table);
		infolPane.setBounds(10, 151, 921, 339);
		
		
		contentPane.add(infolPane);
		this.setLocationRelativeTo(null);
		this.setVisible(true);
	}
	
	//设置model的值
	public void setModel(List<Client>  lsit) {
		Vector<String> headerVector =  new Vector<>();
		headerVector.add("宾客姓名");
		headerVector.add("性别");
		headerVector.add("证件类型");
		headerVector.add("证件编号");
		headerVector.add("详细地址");
		Vector<Vector<String>> body = new Vector<>();
		 new Select().findAllCllient();
		for(Client a :lsit){
			Vector<String> v =new Vector<>();
			v.add(a.getC_name());
			v.add(a.getC_gender());
			v.add(a.getC_card_type());
			v.add(a.getC_card());
			v.add(a.getC_address());
			body.add(v);
		}
		if (model ==null){
			model =new DefaultTableModel(body,headerVector);
		}
		model.setDataVector(body,headerVector);
	}
}
